﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Comm.Crypt;

namespace FileCryt
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void btnChoose_Click(object sender, RoutedEventArgs e)
        {
            System.Windows.Forms.OpenFileDialog ofd = new System.Windows.Forms.OpenFileDialog();
            if (ofd.ShowDialog() != System.Windows.Forms.DialogResult.OK)
                return;

            this.tbFile.Text = ofd.FileName;
        }

        private void btnDe_Click(object sender, RoutedEventArgs e)
        {
            byte[] enBytes = System.IO.File.ReadAllBytes(this.tbFile.Text);
            byte[] deBytes = Comm.Crypt.SchemeCrypt.Instance.Decrypt(enBytes);
            System.IO.File.WriteAllBytes(this.tbFile.Text, deBytes);
            MessageBox.Show("已解密");
        }

        private void btnEn_Click(object sender, RoutedEventArgs e)
        {
            byte[] deBytes = System.IO.File.ReadAllBytes(this.tbFile.Text);
            byte[] enBytes = SchemeCrypt.Instance.Encrypt(deBytes);
            System.IO.File.WriteAllBytes(this.tbFile.Text, enBytes);
            MessageBox.Show("已加密");
        }
    }
}
